#!/usr/bin/python
# -*- coding: utf-8 -*
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.cli import CLI
from mininet.link import TCLink
from mininet.node import OVSKernelSwitch, UserSwitch
import time

######################################################################################
#bw=50
#loss=0
#delay='500ms'
######################################################################################
#
#		 bw,loss,delay
#
#		    ____s3____
#		   /          \
#		  1	       　　1
#		[r1]	       [r2]
#		0 	         　　　0
#	    /                  \ 
#	   /	      		  　\
#	  s1	      		   　s2
#	  /		      	    　　　\
#	 /			     　　　　　\
#	h1			     　　　　　h2
# 10.0.0.1/24                10.0.0.100/24
######################################################################################

net = Mininet( cleanup=True )
h1 = net.addHost('h1',ip='10.0.0.1')
h2 = net.addHost('h2',ip='10.0.0.100')
s1 = net.addSwitch('s1')
s3 = net.addSwitch('s3')
r1 = net.addHost('r1')
#r2 = net.addHost('r2')
c0 = net.addController('c0')
#h1
net.addLink(h1,s1,intfName1='h1-eth0',intfName2='s1-eth0',cls=TCLink,bw=100, delay='10ms')
#r1
net.addLink(s1,r1,intfName1='s1-eth1',intfName2='r1-eth0',cls=TCLink,bw=100, delay='10ms')
#s3
net.addLink(r1,s3,intfName1='r1-eth1',intfName2='s3-eth0',cls=TCLink,bw=100, delay='10ms')
#h2
net.addLink(s3,h2,intfName1='s3-eth1',intfName2='h2-eth0',cls=TCLink,bw=100, delay='10ms')
net.build()


#print "build bridge r1-eth0  r1-eth1 "
#r1.cmd("ifconfig r1-eth0 10.0.0.10/24")
#r1.cmd("ifconfig r1-eth1 10.0.0.50/24")


'''
r1.cmd("brctl addbr br_r1")
r1.cmd("brctl addif br_r1 r1-eth0")
r1.cmd("brctl addif br_r1 r1-eth1")
r1.cmd("ifconfig br_r1 up")
'''

net.start()
time.sleep(1)
CLI(net)
net.stop()


